package test;

import cn.hutool.json.JSONUtil;
import okhttp3.*;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;


public class Main {

    public static void main(String[] args) throws IOException {
        // 设置OkHttpClient的一些选项
        OkHttpClient client = new OkHttpClient.Builder()
                .followRedirects(true)  // 设置是否跟随重定向，默认为true
                .connectTimeout(10, java.util.concurrent.TimeUnit.SECONDS)  // 连接超时时间
                .readTimeout(10, java.util.concurrent.TimeUnit.SECONDS)  // 读取超时时间
                .writeTimeout(10, java.util.concurrent.TimeUnit.SECONDS)  // 写入超时时间
                .build();

        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, "{\n  \"other_status\": \"0\",\n  \"authority_id\": \"\",\n  \"team_institution_id\": \"\",\n  \"create_time_start\": \"\",\n  \"create_time_end\": \"\",\n  \"shopId\": \"\",\n  \"page_index\": 1,\n  \"page_size\": 10,\n  \"platform_id\": 3\n}");

        Request request = new Request.Builder()
                .url("https://test-partner-api.chaoyongtuan.com/api/sample-order/sample-list?im=")
                .post(body)
                .addHeader("content-type", "application/json")
                .addHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:130.0) Gecko/20100101 Firefox/130.0")
                .addHeader("Accept", "application/json, text/plain, */*")
                .addHeader("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2")
                .addHeader("applicationId", "1")
                .addHeader("Custom-Cookie", "token=6f88cfe1d2aa308f4ad4d93933ac99fd3bbe81d1")
                .addHeader("authorization", "Bearer 6f88cfe1d2aa308f4ad4d93933ac99fd3bbe81d1")
                .addHeader("data-view-id", "30")
                .addHeader("tenant-id", "4")
                .addHeader("burial-point", "0")
                .addHeader("Origin", "https://test-partner.chaoyongtuan.com")
                .addHeader("Connection", "keep-alive")
                .addHeader("Referer", "https://test-partner.chaoyongtuan.com/")
                .addHeader("Cookie", "public_di=JVwoH0vHmHbExdSdJS8A3xB1Or-cGCfl")
                .addHeader("Sec-Fetch-Dest", "empty")
                .addHeader("Sec-Fetch-Mode", "cors")
                .addHeader("Sec-Fetch-Site", "same-site")
                .addHeader("Priority", "u=0")
                .build();

        try (Response response = client.newCall(request).execute()) {
            ResponseBody responseBody = response.body();
            if (responseBody != null) {
                String responseBodyString = responseBody.string();
                String contentType = response.header("Content-Type");
                System.out.println(responseBodyString);
                System.out.println(contentType);
                // 使用cn.hutool中的方法将响应信息转换为 map 对象
                Map<String, Object> responseMap = JSONUtil.toBean(responseBodyString, Map.class);
                System.out.println(responseMap);
                System.out.println(responseMap.get("data"));
                //



            }
        }
    }
}